package com.lu.statistics.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lu.statistics.entity.*;
import com.lu.statistics.entity.enums.ChoiceTypeEnum;
import com.lu.statistics.entity.front.response.*;
import com.lu.statistics.mapper.MtDishInfoMapper;
import com.lu.statistics.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProGroupServiceImpl implements ProGroupService {
    @Autowired
    private WeddingService weddingService;
    @Autowired
    private WeddingHostsService hostsService;
    @Autowired
    private WeddingPhotographersService photographersService;
    @Autowired
    private WeddingSingersService singersService;
    @Autowired
    private DishInfoService dishInfoService;
    @Autowired
    private DishCategoriesService dishCategoriesService;

    @Override
    public ProGroupResponse queryPageWedding(int pageNo, int pageSize) {
        ProGroupResponse groupResponse = new ProGroupResponse();
        List<WeddingResponse> newList = new ArrayList<>();
        IPage page = weddingService.queryPageWeddingList("LISTING", pageNo, pageSize);
        if (page.getTotal() > 0) {
            for (Object item : page.getRecords()) {
                MtWedding wedding = (MtWedding) item;
                WeddingResponse weddingResponse = new WeddingResponse();
                String url = "/api/file/previewPhoto?fileFullPath=" + wedding.getImgUrl();
                BeanUtils.copyProperties(wedding, weddingResponse);
                weddingResponse.setImgUrl(url);
                newList.add(weddingResponse);
            }
            groupResponse.setWeddingTotal(page.getTotal());
        }
        groupResponse.setWeddingList(newList);
        return groupResponse;
    }

    @Override
    public ProGroupResponse queryPageHostList(int pageNo, int pageSize) {
        ProGroupResponse groupResponse = new ProGroupResponse();
        List<WeddingHostsResponse> newList = new ArrayList<>();
        IPage page = hostsService.queryPageHosts(ChoiceTypeEnum.SINGLE_WEDDING.name(), pageNo, pageSize);
        if (page.getTotal() > 0) {
            for (Object item : page.getRecords()) {
                MtWeddingHosts hosts = (MtWeddingHosts) item;
                WeddingHostsResponse hostsResponse = new WeddingHostsResponse();
                String url = "/api/file/previewPhoto?fileFullPath=" + hosts.getImgUrl();
                BeanUtils.copyProperties(hosts, hostsResponse);
                hostsResponse.setImgUrl(url);
                newList.add(hostsResponse);
            }
            groupResponse.setHostTotal(page.getTotal());
        }
        groupResponse.setHostList(newList);
        return groupResponse;
    }

    @Override
    public ProGroupResponse queryPagePhotographerList(int pageNo, int pageSize) {
        ProGroupResponse groupResponse = new ProGroupResponse();
        List<WeddingPhotographersResponse> newList = new ArrayList<>();
        IPage page = photographersService.queryPagePhotographers(ChoiceTypeEnum.SINGLE_WEDDING.name(), pageNo, pageSize);
        if (page.getTotal() > 0) {
            for (Object item : page.getRecords()) {
                MtWeddingPhotographers photographers = (MtWeddingPhotographers) item;
                String url = "/api/file/previewPhoto?fileFullPath=" + photographers.getImgUrl();
                WeddingPhotographersResponse photographersResponse = new WeddingPhotographersResponse();
                BeanUtils.copyProperties(photographers, photographersResponse);
                photographersResponse.setImgUrl(url);
                newList.add(photographersResponse);
            }
            groupResponse.setPhotographerTotal(page.getTotal());
        }
        groupResponse.setPhotographerList(newList);
        return groupResponse;
    }

    @Override
    public ProGroupResponse queryPagePageSingerList(int pageNo, int pageSize) {
        ProGroupResponse groupResponse = new ProGroupResponse();
        List<WeddingSingersResponse> newList = new ArrayList<>();
        IPage page = singersService.queryPageSingers(ChoiceTypeEnum.SINGLE_WEDDING.name(), pageNo, pageSize);
        if (page.getTotal() > 0) {
            for (Object item : page.getRecords()) {
                MtWeddingSingers singers = (MtWeddingSingers) item;
                WeddingSingersResponse singersResponse = new WeddingSingersResponse();
                String url = "/api/file/previewPhoto?fileFullPath=" + singers.getImgUrl();
                BeanUtils.copyProperties(singers, singersResponse);
                singersResponse.setImgUrl(url);
                newList.add(singersResponse);
            }
            groupResponse.setPhotographerTotal(page.getTotal());
        }
        groupResponse.setSingerList(newList);
        return groupResponse;
    }

    @Override
    public ProGroupResponse queryGroupDishList(int pageNo, int pageSize) {
        ProGroupResponse groupResponse = new ProGroupResponse();
        MtDishInfo dishInfo = new MtDishInfo();
        dishInfo.setCategoriesId(0);
        dishInfo.setChoiceType(ChoiceTypeEnum.SINGLE_DISH.name());
        DishIGroupResponse dishIGroupResponse = dishInfoService.queryGroupDish(dishInfo, pageNo, pageSize);
        groupResponse.setCuisineList(dishIGroupResponse.getCuisineList());
        groupResponse.setLiquorList(dishIGroupResponse.getLiquorList());
        groupResponse.setDishTotal(dishIGroupResponse.getDishTotal());
        return groupResponse;
    }

    @Override
    public ProGroupResponse queryDishDishCategories(int pageNo, int pageSize) {
        ProGroupResponse groupResponse = new ProGroupResponse();
        String isAvailable = "LISTING";
        IPage page = dishCategoriesService.queryDishDishCategories(isAvailable, pageNo, pageSize);
        List<DishCategoriesResponse> newList = new ArrayList<>();
        for (Object item : page.getRecords()) {
            MtDishCategories dishCategories = (MtDishCategories) item;
            String url = "/api/file/previewPhoto?fileFullPath=" + dishCategories.getImgUrl();
            DishCategoriesResponse dishCategoriesResponse = new DishCategoriesResponse();
            BeanUtils.copyProperties(dishCategories, dishCategoriesResponse);
            dishCategoriesResponse.setImgUrl(url);
            newList.add(dishCategoriesResponse);
        }
        groupResponse.setCategorieList(newList);
        groupResponse.setCgTotal(page.getTotal());
        return groupResponse;
    }
}
